//
//  ST_ReportPersonController.swift
//  btvideo
//
//  Created by mac on 2019/11/21.
//  Copyright © 2019 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class ST_ReportPersonController: ST_BTLightBarViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        title_nav_btn.setTitleForAllStates("举报")
         
        view.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: statusBarHeight+44, left: 0, bottom: 0, right: 0))
        }
    }

    var userId = ""
    
    
    var video_id:String?
    
    fileprivate var selectedIdx = 0
    
    fileprivate var data_array = ["头像、资料作假","广告、营销","诈骗、托儿","色情低俗","恶意骚扰、不文明语言"]
    
    lazy var tableView:UITableView = {
            
        let control = UITableView()
        
        control.delegate = self
        
        control.dataSource = self
    
        control.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: BTSafeAreaBottom, right: 0)
        
//            control.rowHeight = UITableView.automaticDimension
        
//            control.estimatedRowHeight = 70
        
        control.register(cellWithClass: ReportPersonCell.self)
        if #available(iOS 11.0, *) {
            control.contentInsetAdjustmentBehavior = .never
        }
        control.separatorStyle = .none
        
        control.backgroundColor = Color.white
//        control.backgroundColor = Color.random
        control.showsVerticalScrollIndicator = false
        control.showsHorizontalScrollIndicator = false
        return control
    }()
    
//    lazy var confirm_btn:UIButton = {
//
//       let btn = UIButton.init(type: UIButton.ButtonType.custom)
//        btn.backgroundColor = Color.init(hex: 0xFEC207)
//        btn.cornerRadius = 20
//        btn.setTitleForAllStates("提交")
//        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.semibold)
//        btn.add_touch_up(insideTarget: self, action: #selector(confirm_handle))
//
//       return btn
//   }()
    
    
//    @objc func confirm_handle(){
//    }
}

extension ST_ReportPersonController:UITableViewDelegate,UITableViewDataSource{
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data_array.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withClass: ReportPersonCell.self, for: indexPath)
        
        cell.singalBtn.isSelected = indexPath.row == self.selectedIdx
        cell.singalBtn.tag = 1024 + indexPath.row
        cell.content_label.text = data_array[indexPath.row]
        
//        cell.click_closure = {[weak self] idx in
//            self?.selectedIdx = idx
//            self?.tableView.reloadData()
//        }
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        
        if let item = data_array[safe:indexPath.row]{
            
            let vc =  ST_ReportDetailController()
            vc.target_accid = userId
            vc.comments = item
            vc.video_id = video_id
            navigationController?.pushViewController(vc)
        }
    }
    
}


//MARK: - Cell
class ReportPersonCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        
        contentView.backgroundColor = UIColor.white
        
        contentView.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(25)
            make.centerY.equalToSuperview()
            make.height.equalTo(24)
        }
        
        contentView.addSubview(singalBtn)
        singalBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-10)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(24)
        }
        
        line.backgroundColor = Color.init(hex: 0xF2F4F7)
        
        contentView.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.bottom.right.equalToSuperview()
            make.height.equalTo(1)
            make.left.equalToSuperview().offset(25)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
//        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.regular)
        return control
    }()
    
    lazy var singalBtn:UIButton = {
       
        let btn = UIButton.init(type: UIButton.ButtonType.custom)
          
        btn.setImageForAllStates(ST_ImageUtils.imageName("个人中心_icon_下一页")!)
//        btn.setImage(ST_ImageUtils.imageName("个人中心_icon_选择sel")!, for: UIControl.State.selected)
//        btn.add_touch_up(insideTarget: self, action: #selector(click(sender:)))
        return btn
    }()
    
    
    lazy var line = UIView()
    
//    var click_closure:((Int)->())?
//
//    @objc func click(sender:UIButton){
//
//        if sender.isSelected{
//            return
//        }
//        sender.isSelected = true
//
//        let idx = sender.tag - 1024
//
//        click_closure?(idx)
//
//    }
   
}
